package com.hinacom.pix.entity;

import org.apache.commons.lang.NullArgumentException;
import org.apache.commons.lang.StringUtils;

import java.lang.String;
import java.util.UUID;

/**
 * Created by fyu on 2016/8/31.
 */
public class PatientIdentifier {
    private String id;
    private String checkDigit;
    private String schemeEmployed;
    private AssigningAuthority assigningAuthority;
    private String identifierTypeCode;
    private AssigningAuthority assigningFacility;

    public String getId() {
        if(StringUtils.isEmpty(this.id))
        {
            this.id = UUID.randomUUID().toString();
        }
        return this.id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getCheckDigit() {
        return checkDigit;
    }

    public void setCheckDigit(String checkDigit) {
        this.checkDigit = checkDigit;
    }

    public String getSchemeEmployed() {
        return schemeEmployed;
    }

    public void setSchemeEmployed(String schemeEmployed) {
        this.schemeEmployed = schemeEmployed;
    }

    public AssigningAuthority getAssigningAuthority() {
        return assigningAuthority;
    }

    public void setAssigningAuthority(AssigningAuthority assigningAuthority) {
        this.assigningAuthority = assigningAuthority;
    }

    @Override
    public String toString() {
        String sId;
        if(this.getId() == null)
        {
            throw new NullArgumentException("The field is required");
        }
        else
        {
            sId = this.getId();
        }

        String sCheckDigit;
        if(this.getCheckDigit()==null)
        {
            sCheckDigit = "";
        }
        else
        {
            sCheckDigit = this.getCheckDigit();
        }

        String sSchemeEmployed;
        if(this.getSchemeEmployed()==null)
        {
            sSchemeEmployed = "";
        }
        else
        {
            sSchemeEmployed = this.getSchemeEmployed();
        }

        String result = String.format("%s^%s^%s^%s",sId,sCheckDigit,sSchemeEmployed,this.getAssigningAuthority().toString());
        return result;
    }

    public AssigningAuthority getAssigningFacility() {
        return assigningFacility;
    }

    public void setAssigningFacility(AssigningAuthority assigningFacility) {
        this.assigningFacility = assigningFacility;
    }

    public String getIdentifierTypeCode() {
        return identifierTypeCode;
    }

    public void setIdentifierTypeCode(String identifierTypeCode) {
        this.identifierTypeCode = identifierTypeCode;
    }
}
